package com.example.demo.controller.AuthorControl;

import com.example.demo.entity.BackResponseEntity;
import com.example.demo.entity.requestJson.AFavoriteAuthorReq;
import com.example.demo.entity.requestJson.DeleteReq;
import com.example.demo.entity.requestJson.IsFavoriteReq;
import com.example.demo.entity.responseJson.AFollowingRes;
import com.example.demo.entity.responseJson.ListResult;
import com.example.demo.service.AFavoriteAuthorService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : 杨丽辉
 * @date : 2021/3/6 15:26
 * @description:
 */
@RestController
@RequestMapping("/author/favoriteauthor")
@Api(value = "关注作者接口", tags = "关注作者接口")
public class AFavoriteAuthorController {
    @Autowired
    private AFavoriteAuthorService aFavoriteAuthorService;

    @ApiOperation(value = "用户关注作者接口", notes = "")
    @ApiOperationSupport(author = "杨")
    @ApiResponses(
            @ApiResponse(code = 200, message = "处理成功")
    )

    @PostMapping("/insertfavorite")
    public BackResponseEntity<Object> insertFavorite(@RequestBody AFavoriteAuthorReq aFavoriteAuthorReq) {
        return aFavoriteAuthorService.favoriteAuthor(aFavoriteAuthorReq);
    }

    @ApiOperation(value = "查看是否关注作者接口", notes = "user_id是此时登录的作者id，author_id是被查看的作者id")
    @ApiOperationSupport(author = "杨")
    @ApiResponses(
            @ApiResponse(code = 200, message = "处理成功")
    )

    @GetMapping("/isfavorite")
    public BackResponseEntity<Object> isFavorite(IsFavoriteReq isFavoriteReq) {
        return aFavoriteAuthorService.isfavoriteAuthor(isFavoriteReq);
    }

    @ApiOperation(value = "查看我的关注列表", notes = "传入关注者id")
    @ApiOperationSupport(author = "杨")
    @ApiResponses(
            @ApiResponse(code = 200, message = "处理成功")
    )

    @GetMapping("/queryfollowing")
    public BackResponseEntity<ListResult<List<AFollowingRes>>> queryFollowing(DeleteReq deleteReq) {
        return aFavoriteAuthorService.queryAFollowing(deleteReq);
    }

    @ApiOperation(value = "用户取消作者接口", notes = "")
    @ApiOperationSupport(author = "杨")
    @ApiResponses(
            @ApiResponse(code = 200, message = "处理成功")
    )

    @PostMapping("/unfavorite")
    public BackResponseEntity<Object> untFavorite(@RequestBody IsFavoriteReq isFavoriteReq) {
        return aFavoriteAuthorService.unSubscribe(isFavoriteReq);
    }

    @ApiOperation(value = "查看我的读者列表", notes = "传入作者id")
    @ApiOperationSupport(author = "杨")
    @ApiResponses(
            @ApiResponse(code = 200, message = "处理成功")
    )

    @GetMapping("/queryreader")
    public BackResponseEntity<ListResult<List<AFollowingRes>>> queryReader(DeleteReq deleteReq) {
        return aFavoriteAuthorService.queryReader(deleteReq);
    }
}
